﻿@model HmPMer.Entity.Notice
@{
   Layout = "~/Views/Shared/_Content.cshtml";
}

<style>
    .linksAdd .layui-form-label {
        width: 100px;
    }

    .linksAdd .layui-input-block {
        margin-left: 120px;
    }
</style>
<body class="childrenBody">
    <form class="layui-form linksAdd" id="formdata">
        @Html.Hidden("Id", Model.Id)
        <div class="layui-form-item">
            <label class="layui-form-label">公告标题</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="Title" name="Title" value="@Model.Title" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公告类别</label>
            <div class="layui-input-block">
                <input type="radio" name="NoticeType" value="1" title="商户" @(Model.NoticeType=="1"?"checked":"") />
                <input type="radio" name="NoticeType" value="2" title="代理"  @(Model.NoticeType=="2"?"checked":"") />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block">
                <div id="editor">@Html.Raw(HttpUtility.UrlDecode(Model.Content))</div>
                <script src="/Scripts/wangEditor.min.js?@ViewBag.StaticVersion"></script>
                <script type="text/javascript">
                    var E = window.wangEditor
                    var editor = new E('#editor')
                    editor.customConfig.uploadImgShowBase64 = true
                    editor.create();
                </script>
                <input type="hidden" id="Content" name="Content" />

                @*<textarea id="Content" name="Content" cols="65" rows="13"></textarea>*@
            </div>
        </div>

        <div class="layui-form-item" style="text-align:center">
            <button class="layui-btn " lay-filter="" style="width:100px" type="button" id="btn_Add">提交</button>
        </div>
    </form>
</body>

<script type="text/javascript" src="/layui/layui.js?@ViewBag.StaticVersion"></script>
<script>

    layui.use(['hm', 'form', 'layer', 'laydate', 'table', 'laytpl'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            hm = layui.hm;

        //提交数据
        $("#btn_Add").click(function () {
            var Title = $("#Title").val();
            if (!Title || Title == "") {
                layer.msg("请输入公告名称！");
                return;
            }


            $('#Content').val(encodeURI(editor.txt.html()));


            var Content = $("#Content").val();
            if (!Content || Content == "") {
                layer.msg("请输入公告内容！");
                return;
            }

            var index = layer.msg('操作中，请稍候', { icon: 16, time: false, shade: 0.8 });
            setTimeout(function () {
                layer.close(index);
                hm.ajax("/System/UpdateNoticeInfo", {
                    data: $("#formdata").serialize(),
                    type: "POST",
                    dataType: 'json',
                    success: function (result) {
                        if (result.Success) {
                            layer.msg("操作成功！", { icon: 1, time: 300 });
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.tableIns.reload();
                            parent.layer.close(index);
                        } else {
                            layer.msg(result.Message);
                        }
                    },
                    error: function (x, t, e) {
                        layer.closeAll();
                    }
                });

            }, 500);

        });

    })
</script>

